(function () {
    $.ajax({
        url: "http://8.142.1.120/khaan/oauth/token",
        type: "POST",
        dataType: "json",
        data: JSON.stringify({
            username: "nongxueyuan",
            password: md5("000000"),
            grant_type: "password",
            scope: "server"
        }),
        headers: {
            "Content-Type": "application/json;charset=UTF-8",
            //在这里向请求头中加入token携带发送
            Authorization: "Basic dGVzdDp0ZXN0",
        },
        success: function (data) {
            console.log(data);
            console.log(data.access_token);//token
            // console.log(data.tenants[0].id);//租户id
            // console.log(data.tenants[0].rootTeamId);//组织id
            //存用户信息， token, 租户id， 组织id
            var user = {
                token: data.access_token,
                tenant_id: data.tenants[0].id,
                team_id: data.tenants[0].rootTeamId
            };
            user = JSON.stringify(user);
            setCookie("user", user);

            // 默认是加载andon.html页面
            $("#main").load("/pages/home.html");
        },
        error: function (err) {
            console.log("error...");
        }

    })
})();
// 底部导航条的点击事件
$("#footer .item").click(function () {
    var index = $(this).index();
    console.log(index);
    switch (index) {
        case 0:
            $("#main").load("/pages/home.html");
            break;
        case 1:
            $("#main").load("/pages/caigou.html");
            break;
        case 2:
            $("#main").load("/pages/chart.html");
            break;

    }
})